const { Control_Listen, UI_Listen ,UI_Layer} = require("../../config/ui_def");
import { WX_AD_CONFIG, Sdk_Platform, VIVO_AD_CONFIG } from '../../frame/constants';
cc.Class({
    extends: cc.Component,
    properties: {
        left_node: cc.Node,
        right_node: cc.Node,
        finger_node: cc.Node,
        adBanner: cc.Node,
    },
    initPage() {
        this.backGroundButton = this.uiBase.background_node.getComponent(cc.Button)
    },
    updatePage() {
        he.voice.playEffect('short', 'voice')
        this.adSwitch(true)
        this.backGroundButton.enabled = false
        this.finger_node.x = 0
        this.right_node.x = 100
        this.left_node.x = -100
        gg.eventManager.on('startGuide', this.listenClient, this)
        this.left_ani = cc.tween(this.left_node)
            .repeatForever(
                cc.tween().by(1, { x: -50 })
                    .by(1, { x: 50 })
            ).repeatForever().start()
        this.right_ani = cc.tween(this.right_node)
            .repeatForever(
                cc.tween().by(1, { x: 50 })
                    .by(1, { x: -50 })
            ).repeatForever().start()

        this.finger_ani = cc.tween(this.finger_node)
            .repeatForever(
                cc.tween().by(1, { x: -200 })
                    .by(1, { x: 200 })
                    .by(1, { x: 200 })
                    .by(1, { x: -200 })
            ).repeatForever().start()
    },
    listenClient(code, param, arg) {
        if (code) {
            switch (code) {
                case Control_Listen.CLOSE_START_GUIDE:
                    gg.eventManager.emit('check')
                    this.uiBase.closePage()
                    break
            }
        }
    },
    closeUI() {
        gg.eventManager.off('startGuide', this.listenClient, this)
        gg.eventManager.emit('playground', { type: UI_Listen.PLGD_STARTEND })
        gg.uiManager.closePage(UI_Layer.Msg, 'chayeAdFake')
        this.finger_node.x = 0
        this.adSwitch(false)
        if (this.left_ani) {
            this.left_ani.stop()
            this.left_ani = null
        }

        if (this.right_ani) {
            this.right_ani.stop()
            this.right_ani = null
        }

        if (this.finger_ani) {
            this.finger_ani.stop()
            this.finger_ani = null
        }
    },

    adSwitch(status) {
        if (status) {
            switch (common.sdk_env) {
                case Sdk_Platform.VIVO:
                    // this.adBanner.name = VIVO_AD_CONFIG.bannerId[0]
                    // he.ad.changeBanner(status, this.adBanner)
                    break
            }
        } else {
            //  关掉广告
            switch (common.sdk_env) {
                case Sdk_Platform.VIVO:
                    // this.adBanner.name = VIVO_AD_CONFIG.bannerId[0]
                    // he.ad.changeBanner(status, this.adBanner)
                    break
            }
        }
    },
});
